package com.example.mydataaccesssample.data;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class CDbManager extends SQLiteOpenHelper {

	public CDbManager(Context context) {
		//創立資料庫
		super(context, "dbMeeting.db", null, 1);
	}
	
	
	public void deleteData(String strTableName,String intPK){
		getWritableDatabase().delete(
				strTableName, 
				"_id="+String.valueOf(intPK),
				null);
	}
	
	public void updateData(String strTableName,ContentValues valueData, String _id){
		getWritableDatabase().update(
				strTableName, 
				valueData, "_id="+
				String.valueOf(_id), 
				null);
	}
	
	
	
	public void newData(String strTableName,ContentValues valueData){
		getWritableDatabase().insert(strTableName, null, valueData);
	}
	
	public Cursor GetBySql(String strSql){
		return getWritableDatabase().rawQuery(strSql, null);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String strSchema = "CREATE TABLE tMeeting";
			   strSchema +="(_id INTEGER PRIMARY KEY,";
			   strSchema +="fid TEXT NOT NULL,";
			   strSchema +="fSubject TEXT NOT NULL,";
			   strSchema +="fDate TEXT,";
			   strSchema +="fTime TEXT,";
			   strSchema +="fLocation TEXT);";
		//創立資料表
		db.execSQL(strSchema);
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		

	}

}
